/*  SSEventView.h
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software Ltd
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */
//  Created by Tobias Haughton on Wed Jan 22 2003.
//

#import <AppKit/AppKit.h>
#import "SSConst.h"
#import "SSEventTextField.h"
#import "SSEBDateFormatter.h"
#import "SSSourceFormatter.h"
#import "SSTextEntryValidationMK2.h"

@class SSEventObject;

@interface SSEventView : NSView<NSCoding> {
   NSBezierPath *borderPath, *gridPath;
   NSPoint distanceFromOrigin;
   SSEventObject *owner;
   SSEventTextField *sourceField, *actorField, *actionField, *beginDateField, *endDateField, *objectField, *locationField, *selectedField;
   BOOL isGhostView;
   BOOL isLinking;
   NSAttributedString *questionString, *addressString;
   int numFields;
   SSEBDateFormatter *dateFormatter;
   SSSourceFormatter *sourceFormatter;
   BOOL isSelected;
   float lastXPosition;
   NSTimer *undoMovementTimer;
   int ssDisplayMode;
   int draggingMode;
   NSCursor *stretchCursor;

   NSPoint leftPoint;
   NSPoint rightPoint;
   NSPoint topPoint;
   NSPoint bottomPoint;
   NSPoint centerPoint;
   NSPoint leftTopPoint;
   NSPoint leftBottomPoint;
   NSPoint rightTopPoint;
   NSPoint rightBottomPoint;
   NSPoint topLeftPoint;
   NSPoint topRightPoint;
   NSPoint bottomLeftPoint;
   NSPoint bottomRightPoint;
}

- (id)initWithFrame:(NSRect)frame owner:(SSEventObject *)own isGhostView:(BOOL)ghost;
- (id)initWithEventView:(SSEventView *)view; //used when printing and exporting

+ (int)numberOfDisplayedFields;

- (SSEventObject *)owner;

- (void)setupForDisplay;
- (void)setPaths;
- (void)setOwner:(SSEventObject *)own;
- (void)setTextFields;
- (void)setSelectedField:(SSEventTextField *)field;
- (SSEventTextField *)selectedField;
- (void)setConnectionPoints;
- (void)selectNextField;

- (void)allowEditingInFieldAtPoint:(NSPoint)point;

- (void)setIsGhostView:(BOOL)isGhost;
- (BOOL)isGhostView;
- (void)setGhostStrings;

- (void)setIsLinking:(BOOL)linking;
- (BOOL)isLinking;

- (void)setViewSize;

- (void)changeActorFieldDisplay:(BOOL)shouldDisplay;
- (void)changeActionFieldDisplay:(BOOL)shouldDisplay;
- (void)changeSourceFieldDisplay:(BOOL)shouldDisplay;
- (void)changeLocationFieldDisplay:(BOOL)shouldDisplay;
- (void)changeObjectFieldDisplay:(BOOL)shouldDisplay;
- (void)changeBeginDateFieldDisplay:(BOOL)shouldDisplay;
- (void)changeEndDateFieldDisplay:(BOOL)shouldDisplay;

- (void)updateDisplayValues;
- (void)updateActor;
- (void)updateAction;
- (void)updateSource;
- (void)updateObject;
- (void)updateLocation;
- (void)updateBeginTime;
- (void)updateEndTime;

- (void)arrangeSubviews;

- (BOOL)isSelected;
- (void)setSelected;
- (void)setUnselected;

- (void)setDistanceFromOrigin:(NSPoint)point;
- (void)setNewOriginWithPoint:(NSPoint)point;

- (BOOL)isFullyWithinRect:(NSRect)rect;

- (NSColor *)color;

- (void)setLastXPosition;
- (float)lastXPosition;

- (void)setMovementUndo:(NSTimer *)timer;

- (int)displayMode;
- (void)setDisplayMode:(int)mode;

- (void)updateOverlapFrameAfterExternalDateChange;
- (void)updateDatesAfterExternalPositionChange;

- (void)setDraggingMode:(int)mode;

- (void)updateDatesAfterDrag;

- (NSComparisonResult)compareDateToEventView:(SSEventView *)eventView;
int sortByYPos( id obj1, id obj2, void *context );

- (NSPoint)leftPoint;
- (NSPoint)rightPoint;
- (NSPoint)topPoint;
- (NSPoint)bottomPoint;
- (NSPoint)centerPoint;
- (NSPoint)leftTopPoint;
- (NSPoint)leftBottomPoint;
- (NSPoint)rightTopPoint;
- (NSPoint)rightBottomPoint;
- (NSPoint)topLeftPoint;
- (NSPoint)topRightPoint;
- (NSPoint)bottomLeftPoint;
- (NSPoint)bottomRightPoint;

@end
